<%@ page language="java" pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>农资与农产品全程供应链物流平台-新增客户信息</title>
<meta name="kewywords" content="农资与农产品全程供应链物流平台"/>
<meta name="description" content="农资与农产品全程供应链物流平台"/>
<link href="css/style.css" type="text/css" rel="stylesheet"/>
<link type="text/css" rel="stylesheet" href="css/jquery-ui.css" />	
<script type="text/javascript" src="js/jquery-1.9.1.js"></script>
<script type="text/javascript" src="js/jquery-ui.js"></script>
<script type="text/javascript" src="js/dialog/lhgdialog.js?skin=default"></script>
<style type="text/css">
	.default {
		background-color: #2672EC;
		color: #fff;font-size:14px;
		width: 84px;height: 30px;
	}
	.c_nobdr{outline:none}
</style>
<script type="text/javascript" src="js/LocalList.js"></script>
		<script type="text/javascript">
		$(document).ready(function(){
			$("a").addClass("myStyle");
			if($("#selectIds").val() != ""){
				var selectIds = $("#selectIds").val();
				if(selectIds == 0){
					$("#male").click();
				}else if(selectIds == 1){
					$("#female").click();
				}					
			}					
		});
		function validatePhoneNo(ph) {
            var pattern = new RegExp(/^[0-9-+]+$/);//^表示开始 $表示结束 右方括号（])后跟+号，意味着这个模式可以重复一次或多次
        	return pattern.test(ph);
        }
        function Check_Mobiles(phone){
        	return (/^((13|15|18|14)+\d{9})$/).test(phone);
        }
		function saveCheck(){
			if($.trim($("#customerName").val()) == ""){
				showTip("请填写客户姓名");
				return false;
			}
			if($.trim($("#telephone").val()) == ""){
				showTip("请填写手机号码");
				return false;
			}else if($.trim($("#telephone").val()) != ""){
				var phone = $("#telephone").val();
				//alert(phone);
				if($.trim(phone).length > 11 || 11 > $.trim(phone).length){
					showTip("请输入11位手机号码");
					return false;
				}else if(!Check_Mobiles(phone)){
					showTip("请输入正确的手机号码");
					return false;
				}					
			}
			if($.trim(document.getElementById("province").value) == ""){
				showTip("请选填省或直辖市");
				return false;
			}
			if($.trim(document.getElementById("district").value) == ""){
				if(document.getElementById("city").value != ""){
					showTip("请选择区");
				}else{
					showTip("请选择市");
				}
				return false;
			}
			if($.trim($("#address").val()) == ""){
				showTip("请填写详细地址");
				return false;
			}
			var labels = getSelectedLabel("province") + ","
				+ getSelectedLabel("city") + "," 
				+ getSelectedLabel("district");
				//alert(labels);
			var values = getSelectedValue("province") + "," +
				getSelectedValue("city") + "," +
				getSelectedValue("district");
				//alert(values);
			$("#areaLabels").val(labels);
			$("#areaValues").val(values);
			$("#saveCustomer").submit();
		}
		/**
		 * 根据<select>标签的id获得当前选中的选项的值和文本
		 */
		function getSelectedLabel(selectId){
			var select = document.getElementById(selectId);
			var index = select.selectedIndex;
			var label = select.options[index].text;				
			return label;
		}
		function getSelectedValue(selectId){
			var select = document.getElementById(selectId);
			var index = select.selectedIndex;
			var value = select.value;
			return value;
		}
		
		function check(val){
			if(val==1){
				if($("#customerName").val() == ""|| $.trim($("#customerName").val()) == ""){
					$("#customerNameTip").html("<font color=\"red\">请填写客户姓名</font>");
					return false;
				}else{
					$("#customerNameTip").html("<font color=\"red\"></font>");	
				}
				
			}	
			if(val==2){
				if ("" == $("#telephone").val() || $.trim($("#telephone").val()) == "") {
					$("#telephoneTip").html("<font color=\"red\">联系电话不能为空</font>");
					return false;
				} else {
					var s= $("#telephone").val();
					var w = 0;   
					for (var i=0; i<s.length; i++) {   
					   var c = s.charCodeAt(i);   
					   //单字节加1   
					   if ((c >= 0x0001 && c <= 0x007e) || (0xff60<=c && c<=0xff9f)) {   
					    w++;   
					   }   
					   else {   
					    w+=2;   
					    
					   }   
					}   
					if (w==11) {   
						$("#telephoneTip").html("<font color=\"red\"></font>");
					}else{
						$("#telephoneTip").html("<font color=\"red\">联系电话必须是11位的数字</font>");
					}   
				}
			}
			if(val==3){
				if($("#address").val() == ""|| $.trim($("#customerName").val()) == ""){
					$("#addressTip").html("<font color=\"red\">请填写详细地址</font>");
					return false;
				}else{
					$("#addressTip").html("<font color=\"red\"></font>");	
				}
				
			}	
		}
		function showTip(alertMessage){
			$.dialog({
				title: "提示",
			    time: 5,
			    lock: true,
			    content: alertMessage,
			    width: 160,
	    		height: 80
			});
		}
	</script>
</head>
<body>
<%@include file="top.jsp" %>
<table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td width="187" height="37" bgcolor="#e0e0e0" class="brt bbt"><div class="topleft fl">系统菜单栏</div></td>
    <td bgcolor="#e7e7e7" class=" bbt"><div class="topleft fl">您现在的位置：<a href="#">首页</a>&nbsp;>&nbsp;<span>客户信息</span></div></td>
  </tr>
  <tr>
    <td width="187" height="100%" valign="top" bgcolor="#FFFFFF" class="brt">
    <div class="left_bk"> 
           <div class="menu2">
            <%@include file="database_left.jsp" %>
        </div>
        </div></td>
    <td align="left" valign="top" bgcolor="#FFFFFF">
    <div class="content">
      <table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
        <tr>
          <td height="38" style="background:url(images/zz_tit.jpg) left top repeat-x;"><div class="tt_back fl">新增客户</div><div class="fr"><img src="images/tit_right.jpg" alt="" width="103" height="38" /></div></td>
        </tr>
        <tr>
          <td class="borders btn"><table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td bgcolor="#fffeee" style="border-bottom:#fee7bd solid 1px;" >
	<form id= "saveCustomer" action="saveCustomer" method="post">
	<s:hidden name="selectIds" id="selectIds"/>
	<s:hidden name="areaLabels" id="areaLabels"/>
	<s:hidden name="areaValues" id="areaValues"/>
	<div style="height:500px">
    <table border="0" cellspacing="0" cellpadding="0" align="left" style="margin-top:20px;margin-left: 100px;margin-bottom: 20px; " >
         <tr style="height: 40px;">
  			<td align="right" width="100px;"><span style="color: red">*</span>客户姓名：</td>
  			<td  width="180px;"><input type="text" class="input_are w122" id="customerName" name="customer.name" value="${customer.name}"  onblur="check(1)"/><span id="customerNameTip"></span></td>
  			</tr>
  		<tr style="height: 40px;">
  			<td align="right"><span style="color: red">*</span>性&nbsp;&nbsp;&nbsp;&nbsp;别：</td>
  			<td width="180px;"><input type="radio" name="customer.sex" id="male" value="0" checked="checked"/>
  					<label for="male">男</label>
					<input type="radio" name="customer.sex" id="female" value="1"/>
					<label for="female">女</label></td>
  			
  		</tr>
  		<tr style="height: 40px;">
  			<td align="right"><span style="color: red">*</span>手机号码：</td>
  			<td width="180px;">
  				<input id="telephone" name="customer.telephone" value="${customer.telephone}" class="input_are w122" onblur="check(2)"/><span id="telephoneTip"></span>
  			</td>
  			</tr>
  			<tr style="height: 40px;">
  			<td align="right">公司名称：</td>
  			<td width="180px;">
				<input type="text" class="input_are w122" name="customer.company" value="${customer.company}" />
  			</td>
  		</tr>
  		<tr style="height: 40px;">
  			<td align="right"><span style="color: red">*</span>区&nbsp;&nbsp;&nbsp;&nbsp;域：</td>
  			<td width="400px;">
  				<div >
  						<script type="text/javascript">
  							var defaultValue = $("#areaValues").val();
  							//alert(defaultValue);
							var options = {
								country: "province",		// “省”下拉列表的名称
								state: "city",				// “市”下拉列表的名称
								city: "district",				// “区”下拉列表的名称
								current: defaultValue,		// 当前默认值，用管道符“|”分割
								language: "zh_cn",			// 数据文件的语言
								path_to_xml: "js/data/china/",	// 数据文件的目录
								read_only: false			// 数据是否只读，若设置为true，则无需设置 country 和 state
							};
							LocalList.mf_init(options);											
						</script>									
  					</div>    			
  			</td>
  		</tr>
  		<tr style="height: 40px;">
  			<td align="right"><span style="color: red">*</span>详细地址：</td>
  			<td width="180px;" >
  				<input type="text" style="width: 250px;"  class="input_are w122" id="address" name="customer.address" value="${customer.address}" onblur="check(3)"/><span id="addressTip"></span>
  			</td>
  		</tr>
  		<tr style="height: 40px;">
  			<td colspan="2" align="center" width="300px;">
  			<input type="button" style="cursor: pointer;" class="buttons2" value="保  存" onclick="saveCheck()" />&nbsp;&nbsp;&nbsp;&nbsp;
  			<input type="reset" style="cursor: pointer;" class="buttons2" value="重  置" /></td>
  		</tr>
</table>
</div>
</form>
</td>
  </tr>
    </table></td>
  </tr>
</table>
</div>
</td>
        </tr>
      </table>
<div class="bottom">版权所有：安徽朗坤物联网</div>
</body>
</html>